package com.hrbxlh.virtualization.websocket;

import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;
import java.util.Map;

/**
 * @author cheer
 */
public class GetHttpSessionConfigurator extends ServerEndpointConfig.Configurator {

    @Override
    @SuppressWarnings("unchecked")
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request,
            HandshakeResponse response) {
        HttpSession httpSession = (HttpSession) request.getHttpSession();
        Map<String, Object> userMsg = (Map<String, Object>) httpSession.getAttribute("userMsg");
        sec.getUserProperties().put("stuorteaId", userMsg.get("stuorteaId"));
        sec.getUserProperties().put("roleId", userMsg.get("roleId"));
        sec.getUserProperties().put("username", userMsg.get("userName"));
    }
}
